package com.yzd.learnjava.generics;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.yzd.learnjava.util.Print;
import com.yzd.learnjava.util.SimpleQueue;

public class Fill {
	public static void main(String[] args) {
		List<Contract> contracts = new ArrayList<Contract>();
		Fill.fill(contracts, Contract.class, 3);
		Fill.fill(contracts, TitleTranfer.class, 2);
		for(Contract c : contracts) {
			Print.print(c);
		}
		
		SimpleQueue<Contract> contractQ = new SimpleQueue<Contract>();
		//Fill.fill(contractQ, Contract.class, 3);
	}
	
	public static <T> void fill(Collection<T> collection, Class<? extends T> classToken, int size) {
		for(int i = 0 ; i < size ; i++) {
			try {
				collection.add(classToken.newInstance());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}

class Contract{
	private static long counter = 0;
	private final long id = counter++;
	public String toString() {
		return getClass().getSimpleName() + " " + id;
	}
}

class TitleTranfer extends Contract{}
